package com.ld.controller;

import com.ld.annotation.LdPermission;
import com.ld.doamin.PageListQuery;
import com.ld.doamin.Permission;
import com.ld.service.IPermissionService;
import com.ld.basic.utils.AjaxResult;
import com.ld.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
@LdPermission(name = "权限操作")
public class PermissionController {

    @Autowired
    private IPermissionService service;

    @PostMapping
    @LdPermission(name = "权限分页")
    public AjaxResult queryPage(@RequestBody PageListQuery query) {
        try {
            PageList<Permission> list = service.queryPage(query);
            return AjaxResult.me().setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("查询失败");
        }

    }

    @GetMapping("/tree")
    @LdPermission(name = "权限树")
    public AjaxResult getTree() {
        try {
            List<Permission> list = service.getTree();
            return AjaxResult.me().setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("查询失败");
        }
    }
}
